package com.pysrc.base.controller;
import com.pysrc.base.service.BaseService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName:
 * @Auther L.Chen
 * @CreateDate
 * @Description TODO
 */
public abstract class BaseController<T> {
    protected BaseService<T> service;

    // RESTful 方法
    @PostMapping(value = "")
    public T insert(@RequestBody T t){
        return service.insert(t);
    }

    @PutMapping(value = "")
    public T update(@RequestBody T t){
        return service.updateByPrimaryKey(t);
    }

    @DeleteMapping(value = "/{id}")
    public T delete(@PathVariable("id")Long id){
        return service.deleteByPrimaryKey(id);
    }

    @GetMapping(value = "/{id}")
    public T select(@PathVariable("id")Long id){
        return service.selectByPrimaryKey(id);
    }

    @GetMapping(value = "")
    public List<T> select(
            T t,
            Integer page,
            Integer pageSize
    ){
        return service.select(t,page,pageSize);
    }

}
